﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RaisingStudio.Data.Common.Expressions
{
    public class SourceCode
    {
        private List<string> sourceArray;
        public List<string> SourceArray
        {
            get { return sourceArray; }
            set { sourceArray = value; }
        }

        private string contens = null;
        public string Contents
        {
            get
            {
                if ((contens == null) && (SourceArray != null))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (int i = 0; i < SourceArray.Count; i++)
                    {
                        string source = SourceArray[i];
                        if (i != SourceArray.Count - 1)
                        {
#if (PocketPC || Smartphone || WindowsCE)
                            stringBuilder.Append(source);
                            stringBuilder.Append("\n");
#else
                            stringBuilder.AppendLine(source);
#endif
                        }
                        else
                        {
                            stringBuilder.Append(source);
                        }
                    }
                    contens = stringBuilder.ToString();
                }
                return contens;
            }
        }

        public const int BUFFER_SIZE = 32;

        public char[] GetContent(int index)
        {
#if (PocketPC || Smartphone || WindowsCE)
            return (Contents.Substring(index, (BUFFER_SIZE > (Contents.Length - index)) ? (Contents.Length - index) : BUFFER_SIZE)).ToCharArray();
#else
            return Contents.ToCharArray(index, (BUFFER_SIZE > (Contents.Length - index)) ? (Contents.Length - index) : BUFFER_SIZE);
#endif
        }
    }
}
